<?php

namespace app\controller;

use app\BaseController;
use app\model\EventLog;
use app\service\Bot;
use think\facade\Log;

class Index extends BaseController
{
    // 入口
    public function index()
    {
        

        // dump($data);
        // Log::write($data);
        // Log::write($_SERVER);
        // Log::write($this->request->header());

        $userAgent =  $this->request->server('HTTP_USER_AGENT');
        
        if(strpos($userAgent,'CQHttp') === 0){

            $data = $this->request->param();

            // 保存日志
            EventLog::create($data);

            // Log::write($data);
            // 回应
            return json(['reply'=>'success']); // 快速操作 reply：内容 auto_escape：是否纯文本发送
        }

        return 'success';
        
    }

    // 初始化面板
    public function init()
    {
        // 获取登录信息
        $user = Bot::get('/get_login_info');

        if($user['state'] == 1){

            // 好友数量
            $user['data']['friend_count'] = Bot::getFriendCount();

            // 群数量
            $user['data']['group_count'] = Bot::getGroupCount();
        }

        

        return json($user);

    }

}
